package com.yc.order.controller;

import com.yc.api.CartApi;
import com.yc.entity.MemberInfo;
import com.yc.entity.OrderInfo;
import com.yc.order.biz.OrderInfoBiz;
import com.yc.order.biz.OrderitemVOBiz;
import com.yc.vo.OrderitemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.relational.core.sql.In;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderitemVOController {

    @Autowired
    private OrderInfoBiz orderInfoBiz;

    @Autowired
    private OrderitemVOBiz orderitemVOBiz;


    @RequestMapping(value = "findByono", method = RequestMethod.GET)
    public List<OrderitemVO> findBymno(@RequestParam Integer page ,HttpSession session) {
        MemberInfo memberInfo = (MemberInfo) session.getAttribute("user");
        List<OrderitemVO> OderitemList = null;
        List<OrderInfo> OrderList=null;
        List<OrderitemVO> OderitemLists = new ArrayList<>();
        if(page==null){
            page = 0;
        }else{
            page =page;
        }
        try {
            OrderList = orderInfoBiz.findBymno(memberInfo.getMno().toString());
            String ono = OrderList.get(page).getOno();
            OderitemList = orderitemVOBiz.findByOno(ono);
            for(OrderitemVO vo :OderitemList){
                String pics = vo.getPics();
                String[] pic = pics.split(";");
                vo.setPics(pic[0]);
                OderitemLists.add(vo);
            }
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }
        return OderitemList;
    }
}
